package com.cnzhizi.multilist;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.cnzhizi.multilist.bean.FilterData;
import com.cnzhizi.multilist.bean.FilterEntity;
import com.cnzhizi.multilist.bean.FilterTwoEntity;
import com.cnzhizi.multilist.utils.ModelUtil;
import com.cnzhizi.multilist.view.FilterView;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    FilterView fvTopFilter;
    private FilterData filterData; // 筛选数据
    private int filterPosition = -1; // 点击FilterView的位置：分类(0)、排序(1)、筛选(2)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fvTopFilter= (FilterView) findViewById(R.id.fv_top_filter);

        // 筛选数据
        filterData = new FilterData();
        filterData.setCategory(ModelUtil.getCategoryData());
        filterData.setSorts(ModelUtil.getSortData());
        filterData.setFilters(ModelUtil.getFilterData());


        // 设置筛选数据
        fvTopFilter.setFilterData(this, filterData);





        // (真正的)筛选视图点击
        fvTopFilter.setOnFilterClickListener(new FilterView.OnFilterClickListener() {
            @Override
            public void onFilterClick(int position) {

                    filterPosition = position;
                    fvTopFilter.showFilterLayout(position);


            }
        });

        // 分类Item点击
        fvTopFilter.setOnItemCategoryClickListener(new FilterView.OnItemCategoryClickListener() {
            @Override
            public void onItemCategoryClick(FilterTwoEntity entity) {
                Toast.makeText(MainActivity.this,entity.getSelectedFilterEntity().getKey()+"被点击",Toast.LENGTH_LONG).show();
            }
        });

        // 排序Item点击
        fvTopFilter.setOnItemSortClickListener(new FilterView.OnItemSortClickListener() {
            @Override
            public void onItemSortClick(FilterEntity entity) {
                Toast.makeText(MainActivity.this,entity.getKey()+"被点击",Toast.LENGTH_LONG).show();
            }
        });

        // 筛选Item点击
        fvTopFilter.setOnItemFilterClickListener(new FilterView.OnItemFilterClickListener() {
            @Override
            public void onItemFilterClick(FilterEntity entity) {
                Toast.makeText(MainActivity.this,entity.getKey()+"被点击",Toast.LENGTH_LONG).show();
            }
        });



    }



}
